// main columns
export function mainColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    {
      type: "selection",
      width: 55,
      align: "center"
    },
    {
      title: this.$t("module.dimension.dimensionCode"),
      key: "dimensionCode",
      minWidth: 120,
      sortable: true,
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.dimensionCode
            }
          },
          params.row.dimensionCode
        );
      }
    },
    {
      title: this.$t("module.dimension.dimensionName"),
      key: "dimensionName",
      minWidth: 120,
      sortable: true,
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.dimensionName
            }
          },
          params.row.dimensionName
        );
      }
    },
    {
      title: this.$t("module.dimension.dataType"),
      key: "dataStructType",
      align: "center",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_6_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_6_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "span",
          params.row.dataStructType == 2
            ? this.$t("module.dimension.dataTypeRadio.list")
            : this.$t("module.dimension.dataTypeRadio.tree")
        );
      }
    },
    {
      title: this.$t("common.describe"), // module.dimension.desc 备注 改为 描述
      key: "description",
      minWidth: 120,
      ellipsis: true,
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.description
            }
          },
          params.row.description
        );
      }
    },
    {
      title: this.$t("common.status"),
      key: "enabled",
      align: "center",
      minWidth: 80,
      maxWidth: 80 + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            // 修改StatusButton内容居中
            style: {
              "justify-content": "center"
            },

            props: {
              status: params.row.enabled == 1 ? "0" : "1"
            }
          },
          params.row.enabled == 1 ? this.$t("common.enable") : this.$t("common.disable")
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "left",
      fixed: "right",
      width: 100,
      render: (h, params) => {
        const hideEditBtn = params.row.dataStructType === 99 // 针对特定类型隐藏编辑按钮
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "md-create",
                text: this.$t("common.edit"),
                hidden: hideEditBtn,
                handle: () => {
                  this.addOrEdit(params.row, true);
                }
              },
              {
                type: "icon",
                icon: "ios-settings",
                text: this.$t("module.dimension.dataSourceManage"),
                handle: () => {
                  this.editDataSource(params.row);
                }
              },
              {
                type: "icon",
                icon: "ios-trash",
                text: this.$t("common.delete"),
                hidden: params.row.enabled == 1,
                handle: () => {
                  this.deleteDimension(params.row);
                }
              }
            ]
          }
        });
      }
    }
  ];
}

export function sourceColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    {
      type: "selection",
      width: 55,
      align: "center"
    },
    // {
    //   title: "所属租户",
    //   key: "tenantCode",
    //   width: 160,
    //   render: (h, params) => {
    //     return h(
    //       "span",
    //       {
    //         attrs: {
    //           title: this.getTenantName(params.row.tenantCode)
    //         }
    //       },
    //       this.getTenantName(params.row.tenantCode)
    //     );
    //   }
    // },
    {
      title: this.$t("module.dimension.dataSourceUrl"),
      key: "dimensionDataUrl",
      align: "left",
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.dimensionDataUrl
            }
          },
          params.row.dimensionDataUrl
        );
      }
    },
    {
      title: this.$t("common.status"),
      key: "enabled",
      align: "center",
      minWidth: 80,
      maxWidth: 80 + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            // 修改StatusButton内容居中
            style: {
              "justify-content": "center"
            },
            props: {
              status: params.row.enabled == 1 ? "0" : "1"
            }
          },
          !!params.row.enabled ? this.$t("common.enable") : this.$t("common.disable")
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "left",
      fixed: "right",
      width: 80,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "md-create",
                text: this.$t("module.dimension.dataSourceManage"),
                handle: () => {
                  this.addOrEditDataSource(params.row);
                }
              },
              {
                type: "icon",
                icon: "md-search",
                text: this.$t("module.dimension.preview"),
                hidden: this.hidePreviewBtn,
                handle: () => {
                  this.previewDataSource(params.row);
                }
              }
            ]
          }
        });
      }
    }
  ];
}

export function previewSource() {
  return [
    {
      title: this.$t("module.dimension.code"),
      key: "code",
      align: "left",
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.code
            }
          },
          params.row.code
        );
      }
    },
    {
      title: this.$t("module.dimension.name"),
      align: "left",
      key: "name",
      width: 200,
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.name
            }
          },
          params.row.name
        );
      }
    }
  ];
}
